package com.operation.net.controller;


import com.operation.net.common.ApiRestResponse;
import com.operation.net.model.Link;
import com.operation.net.model.NodeData;
import com.operation.net.service.impl.ConnectivelyService;

import com.operation.net.service.impl.SystemService;
import com.operation.net.topology.TopologyDiscovery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RequestMapping("/topo")
@RestController
public class TopologyController {
    @Autowired
    ConnectivelyService connectivelyService;
    @Autowired
    SystemService systemService;

    @Autowired
    TopologyDiscovery topologyDiscovery;

    @PostMapping("/topologyDiscovery")
    public ApiRestResponse topologyDiscovery() throws Exception {

        topologyDiscovery.deviceInterfaceMac();
        topologyDiscovery.neighborMac();
        topologyDiscovery.connectOfAll();
        topologyDiscovery.initConnectively();
        return ApiRestResponse.success();
    }

    @GetMapping("connect")
    public Set<Link> connectivelies(){
        return connectivelyService.selectAllLinks();
    }
    @GetMapping("node")
    public NodeData getNodes(){
        return systemService.selectNodeData();
    }

}


